# encoding = utf-8
class PagesController < ApplicationController
  def home
    @products = Product.order('stock desc').limit(4)
    @blogs = Article.order('created_at desc').limit(4)
  end

  def about
    @title = '关于我们'
  end

  def blog
    if params[:category].nil?
      @articles = Article.order('created_at desc').paginate :page => params[:page],:per_page => PAGE_SIZE
    else
      @current_category = Category.find(params[:category])
      @articles = @current_category.articles.order('created_at desc').paginate :page => params[:page],:per_page => PAGE_SIZE
      @title = @current_category.name
    end

    if !params[:article].nil?
      @article = Article.find(params[:article])
      @current_category = @article.category
      @title = @article.title
    end

    @categories = Category.all
  end
end
